<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SolutionSet Javascript Unit Test - Prototype_SS</title>
<script type="text/javascript" src="../../src/prototype.js"></script>
<script type="text/javascript" src="../../src/solution.js"></script>
<script type="text/javascript" src="../../src/unittest.js"></script>
<style type="text/css">
	@import url(test.css);
	code {font-size: 12px;}
	h4 {display: inline; color: #00CCFF;}
</style>
</head>

<body>
<div id="testlog"></div>
<h2>Test Cookies object</h2>
		
		<h3>Default Cookie Value</h3>
		<code id="default_cookie">
			<script type="text/javascript">
			<!--
				document.write('<h4>Default Cookie value =</h4>' + ' ' + document.cookie);
			-->
			</script>
		</code>
		<h3>Set Cookie</h3>
		<code id="set_cookie">
			<script type="text/javascript">
			  <!--
			  	var myDate = new Date();
				myDate.setFullYear(2010,0,14);
				var newDomain = document.domain;
			  	var setCookie = Solution.util.Cookie.set('ted', myDate, myDate, newDomain);
				document.write('<h4>New set Cookie value (\'ted \')=</h4>' + ' ' + document.cookie);
			  //-->
			</script>
		</code>
		<h3>Get Cookie</h3>
		<code id="get_cookie">
			<script type="text/javascript">
			  <!--
				var getCookie = Solution.util.Cookie.get('ted');
				document.write('<h4>Cookie value (\'ted \')=</h4>' + ' ' + getCookie);
			  //-->
			</script>
		</code>
		<h3>Remove Cookie</h3>
		<code id="remove_cookie">
			<script type="text/javascript">
			  <!--
				var removeCookie = Solution.util.Cookie.remove('ted');
				document.write('<h4>New Cookie value =</h4>' + ' ' + Solution.util.Cookie.get());
			  //-->
			</script>
		</code>
		
		<h3>String.substring extensions: Allows for negative indicies</h3>
		<code id="substring">
			<script type="text/javascript">
			<!--
				var str = "Good Morning";
				document.write("<h4>Full string:</h4> " + str + '<br />');
				var negIndex = -4;
				document.write("<h4>String beginning at index = -4:</h4> " + str.substring(negIndex));
				
			-->
			</script>
		</code>
		
		<h3>String.toDOMNodes</h3>
		<code id="strDOM">
			<script type="text/javascript">
			<!--
				var strNode= "<h3>This is my header</h3><p>Hello World</p>";
				document.write(typeof strNode + '<br />');
				var toDOM = strNode.toDOMNodes();
				document.write(toDOM);
			-->
			</script>
		</code>
		
		<h3>Object.isNumeric</h3>
		<code id="isNumeric">
			<script type="text/javascript">
			<!--
				var strNumbers= "2, 3";
				document.write(Object.isNumeric(String(strNumbers)) + "<br />");
				document.write(typeof strNumbers + "<br />");
				var realNumbers = (2, 3);
				document.write(Object.isNumeric(realNumbers));
			-->
			</script>
		</code>
		
		<h3>Object.toDate</h3>
		<b>11/06/1979, 10:30am = 310750200 (UNIX Time Stamp)</b>
		<br />
		<br />
		<code id="toDate">
			<script type="text/javascript">
			<!--
				var unixDate = 310750200;
				var unixToJs = parseInt(unixDate * 1000);
				var toJSDate = Object.toDate(unixDate);
				var jsSetDate = new Date();
				jsSetDate.setTime(unixToJs);
				
				document.write('<h4>Javascript setDate:</h4> ' + Object.inspect(jsSetDate) + '<br />');
				document.write('<h4>UNIX to Javascript date:</h4> ' + Object.inspect(toJSDate) + '<br />');
				
			-->
			</script>
		</code>
		
		<h3>Object.isObject: For custom objects not native to Javascript</h3>
		<ul style="list-style: none;">
			<li>var isAnArray = new Date();</li>
			<li>var isAnObject = {init:function(){},inot:4};</li>
			<li>var isAStr = 'Hello Chris';</li>
		</ul>
		<code id="isObject">
			<script type="text/javascript">
			<!--
				var isAnArray = new Date();
				var isAnObject = {init:function(){},inot:4};
				var isAStr = 'Hello Chris';
				document.write(typeof isAnObject +'<br />');
				document.write(typeof isAStr +'<br />');
				document.write(typeof isAnArray);
				/*
				document.write('\"isAnArray\": ' + Object.isObject(isAnArray) + '<br />');
				document.write('\"isAnObject\": ' + Object.isObject(isAnObject) + '<br />');
				document.write('\"isAStr\": ' + Object.isObject(isAStr));
				*/
			-->
			</script>
		</code>
		
		<h3>Object.isValidDate</h3>
		<code id="isValidDate">
			<script type="text/javascript">
			<!--
			var realDate = new Date();
			realDate.setTime(0);
			var fakeDate = "07/21/83, 12:59";
			document.write(Object.isValidDate(realDate) + '<br />');
			document.write(Object.isValidDate(fakeDate));
			-->
			</script>
		</code>
		
		<h3>Element.Methods.displayed</h3>
		<p id="show" style="width: 200px; height: 30px; border: 1px solid #000;">I AM displaying something</p>
		<p id="hide" style="width: 200px; height: 30px;border: 1px solid blue;"><span id="hide" style="display: none;">I'm not displaying anything</span></p>
		
		<code id="displayed">
			<script type="text/javascript">
			<!--
			var hiddenEl = $('hide');
			document.write('<h4>Hidden Element:</h4> ' + Element.displayed(hiddenEl) + '<br />');
			var shownEl = $('show');
			document.write('<h4>Visible Element:</h4> ' + Element.displayed(shownEl));	
			-->
			</script>
		</code>
		
		<h3>Element.Methods.positionedZIndex</h3>
		<div id="highest" style="width: 300px; padding: 10px; z-index: 1000; border: 1px solid #000;">
			I'm a div and I have a z-index of 1000.
			<ul style=" padding: 10px; list-style: none;z-index: 10; border: 1px solid blue;">
				<li>I'm a ul and I have a z-index of 10</li>
				<li><a href="" id="linkElement">I'm a link, have a z-index of 1, and am the target of the positionedZIndex method</a></li>
			</ul>
		</div>
		<br />
		<code id="z_index">
			<script type="text/javascript">
			<!--
			var _linkElement = $('linkElement');
			document.write('<h4>Highest z-index present in family:</h4> ' + Element.positionedZIndex(_linkElement));
		
			-->
			</script>
		</code>
		<h3>Element.Methods.getClassObject</h3>
		<div id="oldContainer" class="box {minimize: true, maximize: false, _isTransparent: true} oranges"></div>
		<br />
		<code id="getClassObj">
			<script type="text/javascript">
			<!--
			var testObj = {init: function(){},param: 10};
			document.write(Element.getClassObject(testObj));
			-->
			</script>
		</code>
		
		<h3>Event.observe - gets ID and can be sent to Event.stopObserving to terminate that event handler.</h3>
		<div>
			<ul>
				<li><a id="clickMe" style="cursor: pointer;">Click me</a></li>
				<li>I'm just text</li>
			</ul>
		</div>
		<code id="observeExt">
		<script type="text/javascript">
		<!--
		var testObj = $('clickMe');
		var runObj = testObj.observe('click', flag);
		Event.unObserve(runObj);
		function flag(){
			alert('This works great');
		}
		-->
		</script>
		</code>
		
		
		<h3>Object.shout - extends alert function so can properly alert objects</h3>
		<code id="shout">
			<script type="text/javascript">
			<!--
			
			
			-->
			</script>
		</code>
		
		<h3>Viewport getDimensions</h3>
		<div id="container" style="width: 350px; height: 200px; background-color: black;">
			<p style="width: 200px; height: 40px; margin: auto; text-align: center; padding: 10px; color: #fff; ">This container has a width of 350px and a height of 200px</p>
		</div>
		<br />
		<code id="getDimensions">
			<script type="text/javascript">
			<!--
			var containerDim = $('container').getDimensions();
			document.write('<h4>The div#container has a width of:</h4> ' + containerDim.width + 'px' + '<br />');
			document.write('<h4>The div#container has a height of:</h4> ' + containerDim.height + 'px'); 
			-->
			</script>
		</code>
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[

  new Test.Unit.Runner({
    
	setup: function() {
	
	},
	
	teardown: function() {
	
	},
	
    testSetCookie: function() { with(this) {
		var myDate = new Date();
		myDate.setFullYear(2010,0,14);
		var c = new Solution.util.Cookie.set('ted', myDate, myDate, '.solutionset.com');
		assertInstanceOf(Solution.util.Cookie.set, c);
    }},

    testGetCookie: function() { with(this) {
		var d = new Solution.util.Cookie.get('ted');
		assertInstanceOf(Solution.util.Cookie.get, d);
    }},
    
	testRemoveCookie: function() { with(this) {
		var r = new Solution.util.Cookie.remove('ted');
		assertInstanceOf(Solution.util.Cookie.remove, r);
	}},
    
	testSubstring: function() { with(this) {
		var str = "Good Morning";
		var negIndex = -4;
		assert(negIndex < 0);
		var _subString = str.substring(negIndex);
		assertEqual('ning', _subString);
	}},
	
	testtoDOMNodes: function() { with(this) {
		var strNode = "<h3>This is my header</h3><p>Hello World</p>";
		assertEqual('string', typeof strNode);
		
	}},
	
	testisNumeric: function() { with(this) {
		var strNumbers= "2, 3";
		assertEqual('string', typeof strNumbers);
		var realNumbers = (2, 3);
		assertEqual('number', typeof realNumbers);
	}},
	
	testtoDate: function() { with(this) {
		var unixDate = 310750200;
		var unixToJs = parseInt(unixDate * 1000);
		var toJSDate = Object.toDate(unixDate);
		var jsSetDate = new Date();
		jsSetDate.setTime(unixToJs);
		assertEqual(Object.inspect(jsSetDate), Object.inspect(toJSDate));
	}},
	
	testisObject: function() { with(this) {
		var isAnObject = {init:function(){},inot:4};
		var isCustomObj = isAnObject.toString();
		assertEqual('object', typeof isAnObject);
		assertEqual('[object Object]', isCustomObj);
	}},
	testisValidDate: function() { with(this) {
		var realDate = new Date();
		realDate.setTime(0);
		assertInstanceOf(new Date, realDate);
	}},
	testDisplayed: function() { with(this) {
		var shownEl = $('show');
		assertVisible(shownEl);
		_isVisible(shownEl);
		assertEqual(_isVisible(shownEl), Element.displayed(shownEl));
	}},
	testpositionedZIndex: function() { with(this) {
		var _linkElement = $('linkElement');
		
	}},
	testShout: function() { with(this){
		var newObj = {}
		newObj = {
			initialize: function() {
				this.message();
			},
			message: function(){
				document.write("I'm a new object");
			}
		}
		var shoutObj = shout(newObj);
		wait(1000, shoutObj);		
	}},
	testgetDimensions: function() { with(this){
		var divContainer = $('container');
		var divWidth = divContainer.getStyle('width');
		var divHeight = divContainer.getStyle('height');
		var containerDim = divContainer.getDimensions();
		assertEqual(divWidth, containerDim.width + 'px');
		assertEqual(divHeight, containerDim.height + 'px'); 
	}}
  }, "testlog");
// ]]>
</script>

</body>
</html>
